<!--导航-->
<script>
    var url = document.location.toString();
    var arrUrl = url.split("//");
    var start = arrUrl[1].split("/")[1];
    $(document).ready(function () {
        var num = $("#page_num").val();
        if (num == 1) {
            $("#1").attr("class", "active")
        } else if (num == 2) {
            $("#2").attr("class", "active")
        } else if (num == 3) {
            $("#3").attr("class", "active")
        } else if (num == 4) {
            $("#4").attr("class", "active")
        } else if (num == 5) {
            $("#5").attr("class", "active")
        }
        loadUserInfo();
        $("#logout").click(function () {
            var isLogin= $("#logout").text()
            if (isLogin=="登陆") {
                loginInit()
            }else {
                window.location.href="/logout"
            }
        })
    })

    function loadUserInfo() {
        $.get("/is/login", function (reulst) {
                    if (reulst.code == 200) {
                        $("#logo").html('<a href="index" ><img src="' + reulst.data.icon + '" ></a>');
                        $("#logout").text("登出")
                    } else {
                        $("#logo").html("")
                        $("#logout").text("登陆")

                    }
                }
        )
    }
    function loginInit() {
        document.cookie="redirect_url="+start;
        layer.open({
            btn: '',
            offset: '36%',
            title: '登陆',
            content: '<span id="msg" style="color: red;"></span><br><div ><label>用户名：</label><input type="text" id="username"  style="width: 160px"></div><div style="margin-top: 8px"><label>密&nbsp&nbsp&nbsp&nbsp码：<input type="password" id="password"  style="width: 160px"></label></div>' +
                    '<div style="margin-top: 8px"><a href="/login/qq"><img src="/img/qq_logo_7.png"></a><input type="submit" value="注册" onclick="toregister()" style="margin-left: 40px; display: inline-block;height: 28px;line-height: 28px;padding: 0 18px;background-color: #1E9FFF;color: #fff;white-space: nowrap;text-align: center;font-size: 14px;border: none;border-radius: 2px;cursor: pointer;" ><input type="submit" value="登陆" onclick="login()" style="margin-left: 10px; display: inline-block;height: 28px;line-height: 28px;padding: 0 18px;background-color: #1E9FFF;color: #fff;white-space: nowrap;text-align: center;font-size: 14px;border: none;border-radius: 2px;cursor: pointer;" ></div>'

        });
    }

    function toregister() {
        window.location.href="/login";
    }

    function login() {
        $.ajax({
            url: '/dologin',
            type: 'POST',
            data: "username=" + $("#username").val() + "&password=" + $("#password").val(),
            success: function () {
                $.get("/is/login", function (result) {
                    if (result.code == 400) {
                        $("#msg").html("用户名或密码错误！");
                    } else {
                        document.cookie="redirect_url=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
                        loadUserInfo();
                        layer.alert('&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp登陆成功！', {icon: 1, offset: '260px'});
                    }
                })
            }
        });
    }

    var OriginTitile = document.title;
    var titleTime;
    document.addEventListener('visibilitychange', function () {
        if (document.hidden) {
            document.title = '你快回来！！！';
            clearTimeout(titleTime);
        }
        else {
            document.title = '木石年华';
            titleTime = setTimeout(function () {
                document.title = OriginTitile;
            }, 3000);
        }
    });
</script>
        <style>
            nav .nav-login {
                width: 90px;
                display: block;
                text-overflow: ellipsis;
                white-space: nowrap;
                overflow: hidden;
                border-left: 1px solid #E5E5E5;
            }
            .nav-login  a:hover {
                width: 70px;
                background-color:#3e5dff;
            }
        </style>
<nav class="navbar-fixed-top">
    <div class="container">
        <div class="nav-logo" style="float: left;border-radius:70%;overflow:hidden;" id="logo"></div>
        <div class="nav-menu">
            <span></span>
            <span></span>
            <span></span>
        </div>

        <ul class="nav-list">
            <li><a id="1" href="/index">首页</a></li>
            <li><a id="2" href="/article">日记本</a></li>
            <li><a id="3" href="/message">留言板</a></li>
            <li><a id="4" href="/link">友人帐</a></li>
            <li><a id="5" href="/about">关于我</a></li>
            <li class="nav-login"><a id="logout" style="cursor: pointer" >登陆</a></li>
            <li id="role"></li>
        </ul>
    </div>
</nav>